package com.honor.games.wg.graphics.actors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.google.common.eventbus.EventBus;
import com.honor.games.wg.entities.WGUnit;
import com.honor.games.wg.events.UnitClickedEvent;

public class WGUnitClickListener extends ClickListener {

	private static Logger logger = LoggerFactory.getLogger(WGUnitClickListener.class);
	
	private EventBus eventBus;
	private WGUnitActor unitActor;
	private WGUnit unit;
	
	public WGUnitClickListener(EventBus eventBus, WGUnitActor unitActor, WGUnit unit) {
		this.eventBus = eventBus;
		this.unitActor = unitActor;
		this.unit = unit;
	}
	
	@Override
	public void clicked(InputEvent event, float x, float y) {
		
		logger.trace("Unit clicked: {}, unitId: {}; actorId: {}; location: {}, {}", new Object[]{unit.getUnitType(), unit.getId(), unitActor.getId(), unit.getLocationX(), unit.getLocationY()});
		this.eventBus.post(new UnitClickedEvent(unitActor, unit));	
	}
	
}
